<template>
  <d2-container>
    <template slot="header">
      <div style="display: flex;width: 90%">
        <div style="width: 80%">
          <el-descriptions title="考核详情">
            <el-descriptions-item label="考核号">{{ revalues.appraisalNo }}</el-descriptions-item>
            <el-descriptions-item label="考核名称">{{ revalues.assessName }}</el-descriptions-item>
            <el-descriptions-item label="考核类型">{{ revalues.assessType }}</el-descriptions-item>
            <el-descriptions-item label="创建时间">{{ revalues.createTime }}</el-descriptions-item>
            <el-descriptions-item label="审核人">{{ revalues.checkInfoName }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <div style="width: 20%">
          <div style="display: flex;align-items: center">状态：<h2 style="margin: 0;">{{ revalues.status }}</h2></div>
          <div style="display: flex;align-items: center">得分：<h2>{{ revalues.score }}</h2></div>
        </div>
      </div>
    </template>
    <div style="box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)">
      <div style="padding: 1em;display: flex; width:90%">
        <div style="margin-left: 5%;width: 100%">
          <h2>请输入您的自评：</h2>
          <el-input
            type="textarea"
            :rows="8"
            placeholder="请输入内容"
            v-model="textarea">
          </el-input>
        </div>

        <div style="margin-left: 2%;width: 30%">
          <h2>请上传您的附件</h2>
          <div style="width: 15em">
            <el-upload
              class="upload-demo"
              ref="upload"
              action="#"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :on-change="handleChange"
              :before-remove="beforeRemove"
              :limit=1
              :file-list="fileList"
              :auto-upload=false>
              <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              <!--              <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>-->
              <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload"
                         v-loading.fullscreen.lock="fullscreenLoading">上传到服务器
              </el-button>
              <div slot="tip" class="el-upload__tip">上传附件和自评</div>
            </el-upload>
          </div>
        </div>
      </div>
    </div>

  </d2-container>
</template>

<script>
export default {
  name: 'review',
  data () {
    return {
      fileList: [],
      textarea: '',
      fullscreenLoading: false
    }
  },
  methods: {
    submitUpload () {
      this.fullscreenLoading = true
      const fd = new FormData()
      this.fileList.map((item) => {
        fd.append('file', item.raw)
      })
      fd.append('selfEvaluation', this.textarea)
      fd.append('eid', this.revalues.eid)
      this.$request({ url: '/selfAppraisal/fileUpload', method: 'post', data: fd })
        .then((res) => {
          if (res === 1) {
            this.$emit('submitUpload', 1)
            this.fullscreenLoading = false
          } else {
            this.$message.error('自评或文件不能为空')
            this.fullscreenLoading = false
          }
        })
    },
    handleRemove (file, fileList) {
      console.log(file, fileList)
    },
    handlePreview (file) {
      console.log(file)
    },
    handleChange (file, fileList) {
      this.fileList = fileList
      console.log(this.fileList)
    },
    beforeRemove (file, fileList) {
      this.$confirm(`确定移除 ${file.name}？`).then(res => {
        if (res === 'confirm') {
          this.fileList = []
        }
      })
    }
  },
  props: {
    revalues: {
      type: Object,
      default: null
    }
  }
}
</script>
